/*
 * CRtpPacker.cpp
 *
 *  Created on: 2018年4月21日
 *      Author: zhengboyuan
 */

#include "CRtpPacker.h"

namespace av
{

CRtpPacker::CRtpPacker():
		m_codec()
{
}

CRtpPacker::~CRtpPacker()
{
}

bool CRtpPacker::open()
{
	return true;
}

void CRtpPacker::pack(const MediaPacket& pkt, int maxSize, RtpPackerSink sink)
{
	if (pkt.size <= maxSize)
	{
		RtpPacket pktOut;
		pktOut.data = pkt.data;
		pktOut.size = pkt.size;
		pktOut.ts = (uint32_t)pkt.pts;

		pktOut.mark = true;
		pktOut.pt = m_payload;

		sink(pktOut);
	}
	else
	{
		RtpPacket pktOut;
		pktOut.ts = (uint32_t)pkt.pts;
		pktOut.pt = m_payload;

		uint8_t* p = pkt.data;
		int leftSize = pkt.size;
		while (leftSize > maxSize)
		{
			pktOut.data = p;
			pktOut.size = maxSize;
			pktOut.mark = false;

			p += maxSize;
			leftSize -= maxSize;

			sink(pktOut);
		}

		pktOut.data = p;
		pktOut.size = leftSize;
		pktOut.mark = true;
		sink(pktOut);
	}
}

void CRtpPacker::close()
{
	// pass
}

void CRtpPacker::setCodec(int codec)
{
	m_codec = codec;
}



} /* namespace av */
